package com.liu.designmode.proxy.type;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

import java.util.HashMap;
import java.util.Map;

public class TypeHandlerFactory {


    private static Map<Class, TypeHandler> typeHandlerMap = new HashMap<>();

    static {
        typeHandlerMap.put(Integer.class, new IntegerTypeHandler());
        typeHandlerMap.put(String.class, new StringTypeHandler());

    }

    public static TypeHandler get(Class<?> clz) {
        return typeHandlerMap.get(clz);
    }


//    @Autowired
//    private ApplicationContext applicationContext;
//    public Map<String, TypeHandler> getImplementations() {
//        Map<String, TypeHandler> implementationMap = new HashMap<>();
//        // 获取所有实现 MyInterface 的 Bean
//        String[] beanNames = applicationContext.getBeanNamesForType(TypeHandler.class);
//        for (String beanName : beanNames) {
//            TypeHandler bean = (TypeHandler) applicationContext.getBean(beanName);
//            implementationMap.put(beanName, bean);
//        }
//        return implementationMap;
//    }
}
